<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="标题" prop="sender">
        <el-input v-model="query.title" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <!-- <div class="mid-action">
      <div>
        <el-button type="primary" size="mini" @click="creatItem('creat')">发布消息</el-button>
      </div>
    </div> -->
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="标题" align="center" prop="name" />
      <el-table-column label="内容" align="center" prop="issue" />
      <el-table-column label="发布时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="viewDetail(scope.row)">查看</el-button>
          <!-- <el-button v-hasPermi="['enterpriseWechat:edit']" size="mini" type="text" @click="deleteItem(scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 编辑表单 -->
    <el-dialog title="详情" :visible.sync="editFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-position="left">
        <el-form-item label="标题">
          <el-input class="input" v-model="form.name" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="内容">
          <el-input class="input" type="textarea" v-model="form.issue" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="图片">
          <el-image class="screenshot" fit="fill" :preview-src-list="form.picUrls" :src="item" v-for="(item,index) in form.picUrls" :key="index"></el-image>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getFeedback } from "@/api/eh-api";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 查询参数
      query: {
        pageNum: 1,
        pageSize: 10,
        issue: undefined,
      },
      list:[],
      form:{
        name:'',
        issue:'',
        picUrls:[],
      },
      editFormShow:false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getFeedback(this.query)
        .then(({ rows, total }) => {
          this.list = rows.map( item => {
            item.picUrls ? item.picUrls = item.picUrls.split(',') : item
            return item
          })
          
          this.total = parseInt(total);
          this.loading = false;
          this.ids = [];
        })
        .catch(() => {
          this.loading = false;
        });
    },
    /**
     * 查看详情
     */
    viewDetail:function(row) {
        this.form = row
        this.editFormShow = true
    }
  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}
.screenshot{
  width: 30%;
  height: 500px;
}
</style>
